﻿using System;

namespace CSW.Framework.Common.Utils.ExcelUtils
{
    /// <summary>
    /// Excel RPNToken.
    /// </summary>
    public class RPNToken
    {
        /// <summary>
        /// Initializes a new instance of the <see cref="RPNToken"/> class.
        /// </summary>
        /// <param name="identifier">The identifier.</param>
        /// <param name="attributeType">Type of the attribute.</param>
        /// <param name="data">The data.</param>
        public RPNToken(TokenIdentifier identifier, TokenAttributeType attributeType, byte[] data)
        {
            Identifier = identifier;
            AttributeType = attributeType;
            Data = data;
        }

        /// <summary>
        /// Gets the identifier.
        /// </summary>
        /// <value>The identifier.</value>
        public TokenIdentifier Identifier { get; private set; }

        /// <summary>
        /// Gets the type of the attribute.
        /// </summary>
        /// <value>The type of the attribute.</value>
        public TokenAttributeType AttributeType { get; private set; }

        /// <summary>
        /// Gets the data.
        /// </summary>
        /// <value>The data.</value>
        public byte[] Data { get; private set; }

        /// <summary>
        /// Gets the value of the <see cref="RPNToken"/>.
        /// </summary>
        /// <returns>The value of the <see cref="RPNToken"/>.</returns>
        public object GetValue()
        {
            switch (Identifier)
            {
                case TokenIdentifier.tStr:
                    string strValue = string.Empty;
                    for (int i = 0; i < Data.Length; i++)
                        strValue += (char)Data[i];
                    return strValue;

                default:
                    throw new NotImplementedException(string.Format("GetValue for TokenIdentifier '{0}' not implemented.", Identifier));
            }
        }
    }
}
